package c.e.a.b.e.c;

import java.util.Arrays;
import java.util.RandomAccess;

/* compiled from: com.google.android.gms:play-services-measurement-base@@18.0.0 */
public final class o6<E> extends o3<E> implements RandomAccess {
    public static final o6<Object> d;
    public E[] b;
    public int c;

    static {
        o6 o6Var = new o6(new Object[0], 0);
        d = o6Var;
        o6Var.a = false;
    }

    public o6(E[] eArr, int i) {
        this.b = eArr;
        this.c = i;
    }

    public final /* synthetic */ b5 a(int i) {
        if (i >= this.c) {
            return new o6(Arrays.copyOf(this.b, i), this.c);
        }
        throw new IllegalArgumentException();
    }

    public final boolean add(E e) {
        b();
        int i = this.c;
        Object[] objArr = this.b;
        if (i == objArr.length) {
            this.b = Arrays.copyOf(objArr, ((i * 3) / 2) + 1);
        }
        Object[] objArr2 = this.b;
        int i2 = this.c;
        this.c = i2 + 1;
        objArr2[i2] = e;
        this.modCount++;
        return true;
    }

    public final void c(int i) {
        if (i < 0 || i >= this.c) {
            throw new IndexOutOfBoundsException(d(i));
        }
    }

    public final String d(int i) {
        int i2 = this.c;
        StringBuilder stringBuilder = new StringBuilder(35);
        stringBuilder.append("Index:");
        stringBuilder.append(i);
        stringBuilder.append(", Size:");
        stringBuilder.append(i2);
        return stringBuilder.toString();
    }

    public final E get(int i) {
        c(i);
        return this.b[i];
    }

    public final E remove(int i) {
        b();
        c(i);
        Object[] objArr = this.b;
        E e = objArr[i];
        int i2 = this.c;
        if (i < i2 - 1) {
            System.arraycopy(objArr, i + 1, objArr, i, (i2 - i) - 1);
        }
        this.c--;
        this.modCount++;
        return e;
    }

    public final E set(int i, E e) {
        b();
        c(i);
        Object[] objArr = this.b;
        E e2 = objArr[i];
        objArr[i] = e;
        this.modCount++;
        return e2;
    }

    public final int size() {
        return this.c;
    }

    public final void add(int i, E e) {
        b();
        if (i >= 0) {
            int i2 = this.c;
            if (i <= i2) {
                Object[] objArr = this.b;
                if (i2 < objArr.length) {
                    System.arraycopy(objArr, i, objArr, i + 1, i2 - i);
                } else {
                    Object[] objArr2 = new Object[(((i2 * 3) / 2) + 1)];
                    System.arraycopy(objArr, 0, objArr2, 0, i);
                    System.arraycopy(this.b, i, objArr2, i + 1, this.c - i);
                    this.b = objArr2;
                }
                this.b[i] = e;
                this.c++;
                this.modCount++;
                return;
            }
        }
        throw new IndexOutOfBoundsException(d(i));
    }
}
